package com.yanqu.road.server.logic.recharge.limit.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.entity.mall.LimitBuyResult;
import com.yanqu.road.logic.activity.GuaGiftsConfig.GuaGiftsConfig;
import com.yanqu.road.logic.activity.qixi.QixiConfig;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.guagifts.GuaGiftsMgr;
import com.yanqu.road.server.manger.activity.qixi.QixiMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.GameErrorCode;

public class QixiRmbMallLimit extends BaseActivityMallLimit {

    public QixiRmbMallLimit(long userId, MallInfo mallInfo, ActivityInfo activityInfo) {
        super(userId, mallInfo, activityInfo);
    }

    @Override
    protected int activityCheck() {
        if (activityInfo.getType() == eActivityType.QiXiActivity.getValue()) {
            QixiConfig config = QixiMgr.getConfig();
            if (config == null) {
                return GameErrorCode.E_ACTIVITY_NO_FOUND;
            }
        }

        if (activityInfo.getType() == eActivityType.GuaGiftsActivity.getValue()) {
            GuaGiftsConfig config = GuaGiftsMgr.getConfig();
            if (config == null) {
                return GameErrorCode.E_ACTIVITY_NO_FOUND;
            }
        }
        if (!ActivityMgr.activityInTime(activityInfo)) {
            return GameErrorCode.E_ACTIVITY_NO_IN_TIME_CANNOT_BUY;
        }
        return 0;
    }

    @Override
    protected boolean isSystemUnLock() {
        if (activityInfo.getType() == eActivityType.QiXiActivity.getValue()) {
            return SystemOpenMgr.systemOpen(player, eSystemId.Qixi.getValue());
        }

        if (activityInfo.getType() == eActivityType.GuaGiftsActivity.getValue()) {
            return SystemOpenMgr.systemOpen(player, eSystemId.GuaGifts.getValue());
        }

        return false;
    }

    @Override
    protected LimitBuyResult buyCountLimit() {
        return activityMallCountLimit(player);
    }

    @Override
    protected int logicCheck() {
        return 0;
    }
}